package com.useeinfo.oa.modules.base.entity;

import com.alibaba.fastjson.JSONObject;
import com.useeinfo.framework.extend.entity.SuperClassEntity;
import com.useeinfo.framework.sugar.tools.StringConverters;
import com.useeinfo.oa.modules.security.entity.SystemUser;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

/**
 * 岗位表
 */
@Entity
@Table(name = "position")
public class Position extends SuperClassEntity<Position> {
    /**
     * 岗位名称
     */
    private String name;

    /**
     * 岗位编码 企业ID+时间年月日+3位随机数
     */
    private String code;
    /**
     * 所属企业
     */
    @ManyToOne
    @JoinColumn(name = "enterprise_id")
    private Enterprise enterprise;

    @ManyToMany(mappedBy = "positionSet")
    private Set<Personnel>personnelSet = new HashSet<>();

    @ManyToMany(mappedBy = "positionSet")
    private Set<SystemUser>systemUserSet = new HashSet<>();

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Enterprise getEnterprise() {
        return enterprise;
    }

    public void setEnterprise(Enterprise enterprise) {
        this.enterprise = enterprise;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Set<Personnel> getPersonnelSet() {
        return personnelSet;
    }

    public void setPersonnelSet(Set<Personnel> personnelSet) {
        this.personnelSet = personnelSet;
    }

    public Set<SystemUser> getSystemUserSet() {
        return systemUserSet;
    }

    public void setSystemUserSet(Set<SystemUser> systemUserSet) {
        this.systemUserSet = systemUserSet;
    }

    @Override
    public JSONObject toJSONObject() {
        JSONObject jsonObject = super.toJSONObject();
        jsonObject.put("id",getId());
        jsonObject.put("name", StringConverters.null2String(getName()));
        jsonObject.put("code",StringConverters.null2String(getCode()));
        return jsonObject;
    }
}
